*** Settings ***
Resource   ../Common_Head.robot

*** Keywords ***
Create Tender
    [Documentation]   Create Tender    -Bella
    [Arguments]    ${tenderId}    ${tenderTitle}    ${customer}
    ...    ${modeAir}=${EMPTY}    ${modeFcl}=${EMPTY}    ${modeLcl}=${EMPTY}
    ...    ${tenderLevel}=${EMPTY}    ${Remark}=${EMPTY}
    Click    ${navigation_basic_data_management}
    Click    ${navigation_tender_list}
    Wait For Elements State    ${tender_toolbar_CreateButton}    enabled    60
    Sleep    3
    Click    ${tender_toolbar_CreateButton}
    Wait For Elements State    ${tender_create_TenderId}     enabled
    Wait Until Keyword Succeeds    50    1    Fill Text     ${tender_create_TenderId}    ${tenderId}
    Wait Until Keyword Succeeds    50    1    Fill Text    ${tender_create_TenderTitle}    ${tenderTitle}
    Wait Until Keyword Succeeds    50    1    Fill Text    ${tender_create_Customer}    ${customer}
    Wait Until Search Finished
    Wait For Elements State     ${tender_create_CustomerDropDown}    visible    60    
    Click    ${tender_create_CustomerDropDown}
    Wait Until Search Finished
    IF    '${modeAir}'!='${EMPTY}'
          Check Checkbox    ${tender_create_ModeAir}
    END
    IF    '${modeFcl}'!='${EMPTY}'
          Check Checkbox    ${tender_create_ModeFcl}
    END
    IF    '${modeLcl}'!='${EMPTY}'
           Check Checkbox    ${tender_create_ModeLcl}
    END
    IF    '${tenderLevel}'!='${EMPTY}'
           Select Options By   ${tender_create_Level}    label    ${tenderLevel}
    END
    IF    '${Remark}'!='${EMPTY}'
           Fill Text   ${tender_create_Remark}    ${Remark}
    END
    Click    ${tender_create_SaveButton}
    Wait Until Keyword Succeeds   60    1    Get Element States    ${tender_create_success}     contains    visible
    Wait Until Search Finished
    Sleep    2
    Wait Until Search Finished

Search Tender
    [Documentation]   Search Tender    -Betty
    [Arguments]    ${TENDER_ID}
    Wait Until Search Finished
    Select Options By   ${project_search_criteria}    label    Tender ID
    Select Options By   ${project_search_operator}    label    Equals
    Fill Text    ${project_search_operand}    ${TENDER_ID}
    Click    ${project_search_searchButton}
    Wait Until Search Finished
    Click    xpath = //td[.='${TENDER_ID}']

Delete Tender
    [Arguments]    ${TENDER_ID}
    Wait Until Search Finished
    ${status}    Run Keyword And Return Status    Get Element States    ${navigation_tender_list}    contains    visible
    IF    "${status}" != "True"
        Click    ${navigation_basic_data_management}
    END
    Click    ${navigation_tender_list}
    Wait For Elements State    ${tender_toolbar_CreateButton}    enabled    60
    Sleep    3
    Wait Until Search Finished
    Search Tender    ${TENDER_ID}
    Wait For Elements State    ${tender_toolbar_DeleteButton}    enabled    60
    Wait Until Keyword Succeeds    5x    300ms    Click    ${tender_toolbar_DeleteButton}
    Mouse Move Relative To    ${project_delete_yesButton}    0.0    200
    Wait For Elements State    ${project_delete_yesButton}    visible    60
    Click    ${project_delete_yesButton}
    Wait Until Search Finished